package com.weilai.lzt.sms3;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private EditText editText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = (EditText)findViewById(R.id.openid);
        SharedPreferences read = getSharedPreferences("openid", MODE_WORLD_READABLE);
        String openid = read.getString("openid", "");

        if((openid!=null && !"".equals(openid)) && !"".equals("null")){
            Intent intent=new Intent(MainActivity.this, SuccessActivity.class);
            intent.putExtra("opeind","openid");
            startActivity(intent);
        }
    }

    protected void submitForm(View view){
        editText = findViewById(R.id.openid);
        String openid = editText.getText().toString();

        Log.i("lzt","submitForm被执行了  openid-->:"+openid);
        //步骤2-1：创建一个SharedPreferences.Editor接口对象，lock表示要写入的XML文件名，MODE_WORLD_WRITEABLE写操作
        SharedPreferences.Editor editor = getSharedPreferences("openid", MODE_WORLD_WRITEABLE).edit();
        //步骤2-2：将获取过来的值放入文件
        editor.putString("openid", openid);
        //步骤3：提交
        editor.commit();
        Toast.makeText(getApplicationContext(), "openid设置成功", Toast.LENGTH_LONG).show();

        Intent intent=new Intent(MainActivity.this, SuccessActivity.class);
        intent.putExtra("opeind","openid");
        startActivity(intent);
    }

}
